package cn.dengta.webapp.model;

import java.util.*;

import cn.dengta.common.context.I18N;
import cn.dengta.common.model.ValueProxy;
import cn.dengta.common.model.ValueProxyImpl;
import cn.dengta.context.model.*;
import cn.dengta.webapp.im.dto.ImCommonConfig;
import cn.dengta.webapp.im.dto.MsgConfigDTO;
import cn.dengta.webapp.trade.model.IntimacyLevel;
import lombok.Getter;
import me.codeplayer.util.X;

import static cn.dengta.context.model.ImI18nKey.*;

@Getter
public enum UpgradeBall implements ValueProxyImpl<UpgradeBall, Integer> {
	GIFT(0, "礼物", USER_INTIMACY_UPGRADE_BALL_GIFT, 200),
	CALL(1, "通话", USER_INTIMACY_UPGRADE_BALL_CALL, 100),
	CHAT(2, "聊天", USER_INTIMACY_UPGRADE_BALL_CHAT, 20),
	;
	public final Integer value;
	public String desc;
	public Integer minCoin;
	final ValueProxy<UpgradeBall, Integer> proxy;

	UpgradeBall(Integer value, String label, String desc, Integer minCoin) {
		this.value = value;
		this.desc = desc;
		this.minCoin = minCoin;
		this.proxy = new ValueProxy<>(this, value, label);
	}

	public String getDesc(Language language) {
		return I18N.msg(this.desc, language.locale);
	}

	public MsgConfigDTO.BallAward findAwards(WesKit wesKit, UpgradeBall ball, Integer coin) {
		List<MsgConfigDTO.BallAward> awardList = ImCommonConfig.buildMsgConfig().findBallAwardOrDef(wesKit, ball);
		// 升序
		awardList.sort(Comparator.comparingInt(MsgConfigDTO.BallAward::getMinCoin));
		if (X.isValid(awardList)) {
			int length = awardList.size();
			for (int i = length - 1; i >= 0; i--) {
				if (awardList.get(i).minCoin <= coin) {
					return awardList.get(i);
				}
			}
		}
		return null;
	}

}
